<template>
	<view style="width: 750rpx;">
		<view v-if="panduan == 7" style="position: fixed;width: 310.5rpx;top: 530rpx;left: 220rpx;display: flex;flex-direction: column;align-items: center;z-index: 1212121;">
			<view>
				<image :src="kong" style="width: 310.5rpx;height: 255rpx;vertical-align: middle;"></image>
			</view>
			<view style="font-size: 30rpx;color: #585858;margin: 60rpx 0 30rpx 0;">登录查看详情</view>
			<view style="width: 272rpx;height: 76.6rpx;background: #FF7300;color: #FFFFFF;font-size: 30rpx;font-weight: bold;border-radius: 38.36rpx;line-height: 76.6rpx;text-align: center;" @tap.stop="godenglu">登录</view>
		</view>
		<view style="width: 750rpx;height: 100%;" v-if="panduan_ji == 12">
			<view style="position: fixed;top: 0;width: 750rpx;padding-top: 60rpx;text-align: center;font-size: 32.616rpx;color: #1C202C;background: #FFFFFF;z-index: 121212121;" :class="panduan == 7 ? 'wu_id' : 'you_id'">
				<view style="margin-top: 45rpx;">课程表</view>
			
			</view>
			<view style="position: fixed;top: 130rpx;">
				<view style="display: flex;margin-top: 30rpx;justify-content: space-between;color: #414141;width: 750rpx;box-sizing: border-box;" v-if="panduan != 7">
					<van-tabs swipeable animated :z-index="z_index"  @change="onChange" v-model="active_l"   class="index_tabs" :title-active-color="titleColor" color="#FF7300" >
					  <van-tab title="待上课"  name="danzhifu">
						  <view v-if="list_shuju == 0">
							  <keep-alive>
								 <newjigoushu :list_shuju="list_shuju"></newjigoushu>
							  </keep-alive>
						  </view>
					  </van-tab>
					  <van-tab title="已结束"  name="danzhifu">
						  <view v-if="list_shuju == 1">
							  <keep-alive>
								 <newjigoushu :list_shuju="list_shuju"></newjigoushu>
							  </keep-alive>
						  </view>
					  </van-tab>
					</van-tabs>
				</view>
			</view>
		</view>
		<view style="width: 100%;height: 100%;" v-if="panduan_ji == 24">
			<view style="position: fixed;top: 0;width: 750rpx;padding-top: 60rpx;text-align: center;font-size: 32.616rpx;color: #1C202C;background: #FFFFFF;z-index: 121212121;" :class="panduan == 7 ? 'you_id' : 'you_id'">
				<view style="margin-top: 45rpx;">课程表</view>
				<view style="position: fixed;top: 108rpx;left: 35rpx;z-index: 1212121212;" @tap="go_dingdan" v-if="user_id != ''">订单</view>
			</view>
			<view style="position: fixed;top:160rpx;width: 750rpx;z-index: 121212;" v-if="panduan != 7">
				<van-tabs swipeable animated :z-index="z_index"  @change="onChange" v-model="active"   class="index_tabs" :title-active-color="titleColor" color="#FF7300" >
				  <van-tab title="待上课"  name="danzhifu">
					  <view v-if="list_shuju == 0">
						  <keep-alive>
							  <newjigou :list_shuju="list_shuju"></newjigou>
						  </keep-alive>
					  </view>
				  </van-tab>
				  <van-tab title="待付款"  name="danzhifu">
					  <view v-if="list_shuju == 1">
						  <keep-alive>
							  <newjigou :list_shuju="list_shuju"></newjigou>
						  </keep-alive>
					  </view>
				  </van-tab>
				  <van-tab title="待评论" name="zhaunchangdan">
					  <view v-if="list_shuju == 2">
						  <keep-alive>
						  		<newjigou :list_shuju="list_shuju"></newjigou>			  
						  </keep-alive>
					  </view>
				  </van-tab>
				  <van-tab title="待总结" name="danzhifu">
					  <view v-if="list_shuju == 3">
						  <keep-alive>
						  		<newjigou :list_shuju="list_shuju"></newjigou>			  
						  </keep-alive>
					  </view>
				  </van-tab>
				  <van-tab title="已结束" name="danzhifu">
					  <view v-if="list_shuju == 4">
						  <keep-alive>
								<newjigou :list_shuju="list_shuju"></newjigou>			  
						  </keep-alive>
					  </view>
				  </van-tab>
				</van-tabs>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data(){
			return {
				active_l: 0,
				active: 0,
				money: 10,
				num_li: 132121321,
				bgColor: "#ffffff",
				maskAlpha: 0.8,
				arr_:["待上课","已结束"],
				arr:[1,2,3,4],
				num:0,
				content:"签到",
				list_num:0,
				jigou_id:"",
				num_: 1,
				jigou_daishang:[],
				panduan_ji: "",
				arr_l:["待上课","待付款","待评价","待总结","已结束"],
				user_id: "",
				xuesheng_number: 1,
				status: 2,
				jigou_daishang_:[],
				list_num_: 0,
				jigou_daishang_er: [],
				panduan_shuzi: 1,
				mechanism_id: "",
				master_id: "",
				appointment_id: "",
				master_set_price_id: "",
				study_card_id: "",
				panduan: 6,
				is_comment: false,
				student_id:"",
				currPage: 2, // 当前页码
				totalPage: 2 ,// 总页数
				triggered: false,
				biaoshi_xiala: 11,
				scrollTop: 0,
				yang_biao: 1,
				jigou_daishang_l: [],
				shu_zi: false,
				jigou_number: 1,
				panduan_num: 33,
				content_ji: "总结",
				isshow: true,
				dangqian: "",
				uploadName: {},
				titleColor: "#FF7300",
				list_shuju: 0,
				kong: "http://img.curiousmore.com/968125"
			}
		},
		methods:{
				go_dingdan() {
					uni.navigateTo({
						url:"/pages/Meet/userList/userList"
					})
				},
				goyuyue_ke(){
					uni.navigateTo({
						url:"/pages/Friend/evaluateTeacher/evaluateTeacher"
					})
				},
				onChange(e){
					this.list_shuju =  e.detail.index
				},
				quxiaoyuyue(itme){
					let me = this
					uni.showModal({
					    title: '取消预约',
					    content: '是否取消预约',
					    success: function (res) {
					        if (res.confirm) {
					            me.quxiao(itme)
					        } else if (res.cancel) {
					           
					        }
					    }
					});
				},
			async	quxiao(itme){
					let id = itme.id
					const res = await this.$myRequest({
						url: "/userAppointment/updateCancelCourse",
						data: {
							id: id
						},
						methed: "post",
						header: {
							'content-type': 'application/json'
						}
					})
					if(res.code == 0){
						uni.showToast({
							title: "取消成功"
						})
						setTimeout(() => {
							this.jigou_daishang_ = []
							this.jigou_daishang_er = []
							this.xuesheng_number = 1
							this.status = 2
							this.xuesheng_shuju()
						},100)
					}
				},
				add(){
					uni.navigateTo({
					    url: "/pages/Friend/applyFor/applyFor"
					})
				},
				gozongjie(index,itme){
					let cankao = {
						cankao: index
					}
					if(index == 'zongjie'){
						uni.navigateTo({
							url:"/pages/Friend/setRedPackets/setRedPackets?num=" + encodeURIComponent(JSON.stringify(itme))
						})
					}else{
						uni.navigateTo({
							url:"/pages/Friend/myLanguage/myLanguage?num=" + encodeURIComponent(JSON.stringify(itme))
						})
					}
				},
				zongjie_ji(itme){
					if(itme.you_){
						uni.navigateTo({
							url:"/pages/Friend/talkSet/talkSet?num=" + encodeURIComponent(JSON.stringify(itme))
						})
					}else{
						uni.showToast({
							title: '暂无学生预约',
							icon:"none"
						})
					}
				},
				onRefresh() {
					this.biaoshi_xiala = 22
					this.triggered = true;
					this.jigou_daishang_ = []
					this.jigou_daishang_l = []
					if(this.panduan_ji == 24){
						this.xuesheng_shuju()
					}else{
						this.jigou_xuesheng()
					}
				},
				godenglu(){
					uni.navigateTo({
						url:"/pages/tabBer/login/logins"
					})
				},
				qiandao_xuesheng(itme){
					this.mechanism_id = itme.mechanism_id
					this.master_id = itme.master_id
					this.appointment_id = itme.appointment_id
					this.master_set_price_id = itme.master_set_price_id
					this.study_card_id = itme.study_card_id
					this.student_id = itme.id
					if(this.content == "支付"){
						this.zhifuxiang(itme)
					}else if(this.content == "签到"){
						this.qiandao()
					}else if(this.content == "评价"){
						uni.navigateTo({
						    url: '/pages/Friend/tongxunlu/tongxunlu?num=' + encodeURIComponent(JSON.stringify(itme))
						})
					}else if(this.content == "查看评论"){
						uni.navigateTo({
						    url: '/pages/Friend/chat/chat?num=' + encodeURIComponent(JSON.stringify(itme))
						})
					}
				},
				// 签到
			async 	qiandao(){
						const res = await this.$myRequest({
							url:"/userAppointment/update",
							data:{
								status: "3",
								id: this.student_id
							},
							methed: "post",
							header:{
								'content-type':'application/json'
							}
						})
						if(res.code == 0){
							uni.showToast({
								title:"签到成功"
							})
						}
				   },
		async	xuesheng_shuju(){
				let me = this
				me.shu_zi = false
				if(me.panduan_num == 11){
					me.triggered = true
				}
				if(me.user_id != ""){
					const res = await me.$myRequest({
						url:"/userAppointment/queryOfflineSchedule",
						data:{
							offset: "8",
							user_id: me.user_id,
							type: "mechanism_offline",
							pageSize: 5,
							currentPage: me.xuesheng_number,
							status: me.status,
							is_comment: me.is_comment
						}
					})
					if(res.code == 0){
						if(res.data.length < 10){
							me.panduan_shuzi = 2
						}
						if(res.data.length == 0){
							me.shu_zi = true
						}
						uni.showLoading({
						    title: '加载中'
						});
						let zhiqian = [],zhihou = []
						res.data.forEach((itme,index) => {
							itme.nian =itme.start_time.substring(0,10).replace(/\-/g,"/")
							let dd = me.week_fun(itme.start_time.replace(/\-/g,"/"))
							itme.duan = itme.start_time.substring(11,16) + "-" + itme.end_time.substring(11,16)
							if(itme.map.masterinfo != null && itme.map.masterAppointment != null){
								itme.nick_name = itme.map.masterinfo.nick_name
								itme.avatar = itme.map.masterinfo.avatar
								itme.classroom = itme.map.masterAppointment.classroom
							}else{
								itme.nick_name = "张三"
								itme.avatar = "http://img.curiousmore.com/B94-7F93F340F703/Documents/com_tencent_imsdk_data/image/huihe_982774855"
								itme.classroom = "教育中心"
							}
							itme.week = dd
							if(index == (res.data.length - 1)){
								let d = {
									start_time:""
								}
								res.data.push(d)
							}
							if(res.data[index].start_time.substring(0,10).replace(/\-/g,"/") == res.data[index + 1].start_time.substring(0,10).replace(/\-/g,"/")){
								zhiqian.push(res.data[index])
							}else{
								zhiqian.push(res.data[index])
								zhihou.push(zhiqian.slice(0));
								zhiqian.length = 0;
							}
						})
						zhihou.forEach((itme) => {
							if(itme.length > 1){
								itme.reverse()
							}
						})
						if(me.jigou_daishang_.length == 0){
							me.jigou_daishang_ = zhihou
						}else{
							me.jigou_daishang_ = me.jigou_daishang_.concat(zhihou)
						}
						me.jigou_daishang_er = me.jigou_daishang_
						
						uni.hideLoading()
						setTimeout(() => {
							me.triggered = false
						},1000)
						
					}else{
						uni.showToast({
							title:"未响应",
							icon:"none"
						})
					}
				}
				uni.hideLoading()
			},
		async	zhifuxiang(index){
				const res = await this.$myRequest({
					url: "/rechargerecord/queryPayDetails",
					data: {
						course_num: index.number_of_lessons,
						studycard_id: index.master_set_price_id,
						user_study_card_id: index.study_card_id,
						user_id: this.user_id,
						mechanism_id: this.mechanism_id
					}
				})
				if(res.code == 0){
					this.uploadName = res.data
					let data = Object.assign(res.data,index)
					uni.navigateTo({
					    url: "/pages/Friend/applyFor/applyFor?num=" + encodeURIComponent(JSON.stringify(data))
					})
				}
			},
			huanke(index,itme){
				let me = this
				if(itme == "已结束"){
					me.num_ = 2
					me.dangqian = ""
					me.isshow = false
				}else{
					me.num_ = 1
					me.isshow = true
					me.nian()
				}
				this.scrollTop = 30
				me.jigou_xuesheng()
				me.list_num = index
			},
		async	jigou_xuesheng(){
				let me = this
				me.shu_zi = false
				if(me.biaoshi_xiala != 22){
					uni.showLoading({
					    title: '加载中'
					})
				}
				if(me.jigou_id != undefined){
					const res = await me.$myRequest({
						url:"/masterAppointment/queryMechanismOfflineSchedule",
						data:{
							mechanism_id:me.jigou_id,
							type:"mechanism_offline",
							status:me.num_,
							offset:"8",
							identity_type:"teach_paypal_course",
							pageSize: 10,
							currentPage: me.jigou_number,
							start_time: me.dangqian
						}
					})
					if(res.code == 0){
						let zhiqian = [],zhihou = []
						res.data.forEach((itme,index) => {
							itme.nian =itme.start_time.substring(0,10).replace(/\-/g,"/")
							if(itme.map.studentNum > 0){
								itme.you_ = true
							}else{
								itme.you_ = false
							}
							let dd = me.week_fun(itme.start_time.replace(/\-/g,"/"))
							itme.duan = itme.start_time.substring(11,16) + "-" + itme.end_time.substring(11,16)
							if(itme.map.masterInfo != null){
								itme.nick_name = itme.map.masterInfo.nick_name
								itme.avatar = itme.map.masterInfo.avatar
							}else if(itme.map.masterInfo == null){
								itme.nick_name = "张三"
								itme.avatar = "http://img.curiousmore.com/B94-7F93F340F703/Documents/com_tencent_imsdk_data/image/huihe_982774855"
							}
							itme.week = dd
							if(index == (res.data.length - 1)){
								let d = {
									start_time:""
								}
								res.data.push(d)
							}
							if(res.data[index].start_time.substring(0,10).replace(/\-/g,"/") == res.data[index + 1].start_time.substring(0,10).replace(/\-/g,"/")){
								zhiqian.push(res.data[index])
							}else{
								zhiqian.push(res.data[index])
								zhihou.push(zhiqian.slice(0));
								zhiqian.length = 0;
							}
						})
						zhihou.forEach((itme) => {
							if(itme.length > 1){
								itme.reverse()
							}
						})
						me.jigou_daishang_l = zhihou
						me.jigou_daishang = me.jigou_daishang_l
						if(me.jigou_daishang_l.length == 0){
							me.shu_zi = true
						}
						if(me.biaoshi_xiala == 22){
							if(res.data.length == 0){
								uni.showToast({
									title:"暂无数据",
									icon:"none"
								})
							}else{
								uni.showToast({
									title:"刷新成功"
								})
							}
							me.biaoshi_xiala = 11
							me.triggered = false
							me.scrollTop = 0
						}else{
							if(res.data.length == 0){
								uni.showToast({
									title:"暂无数据",
									icon:"loading"
								})
							}
						}
						uni.hideLoading()
					}else{
						uni.showToast({
							title:"网络错误",
							icon:"none"
						})
					}
				}
			},
			week_fun(index){
				let me = this
				let s = new Date(index).getTime()
				let dd = new Date(s).getDay()
				let d = ""
				if(dd == 1){
					d = "周一"
				}else if(dd == 2){
					d = "周二"
				}else if(dd == 3){
					d = "周三"
				}else if(dd == 4){
					d = "周四"
				}else if(dd == 5){
					d = "周五"
				}else if(dd == 6){
					d = "周六"
				}else if(dd == 0){
					d = "周日"
				}
				let d_ = new Date().getTime()
				if(index.substring(0,10).replace(/\-/g,"/") == me.nian()){
					d = "今日"
				}
				return d 
			},
			nian(){
				let dd = new Date().getTime()
				let s = new Date(dd)
				let nian = s.getFullYear()
				let yue = s.getMonth() + 1 < 10 ? "0" + (s.getMonth() + 1) :  s.getMonth() + 1
				let ri = s.getDate() < 10 ? "0" + s.getDate() : s.getDate()
				this.dangqian = nian + "-" + yue + "-" + ri + " " + "00:00:00"
				return nian + "-" + yue + "-" + ri
			},
			scrolltolower(){
				if(this.panduan_ji == 12){
					if(this.panduan_shuzi == 1){
						this.jigou_number++
						this.jigou_xuesheng()
					}
				}else if(this.panduan_ji == 24){
					if(this.panduan_shuzi == 1){
						this.xuesheng_number++
						this.xuesheng_shuju()
					}
				}
			}
		},
		onLoad() {
			let me = this
			try{
				if(uni.getStorageSync('userif_list')){
					me.jigou_id = uni.getStorageSync('userif_list').mechanism_id
					me.user_id = uni.getStorageSync('userif_list').user_id
				}
				if(uni.getStorageSync('shenfen_')){
					let shenfen = uni.getStorageSync('shenfen_')
					if(shenfen == 55){
						me.panduan_ji = 12
					}else if(shenfen == 33){
						me.panduan_ji = 24
					}
				}else{
					me.panduan_ji = 24
					
				}
			}catch(e){console.log(e)}
			if(me.jigou_id != ""){
				me.nian()
				me.jigou_xuesheng()
			}else if(me.jigou_id == 0){
				me.panduan = 6
				me.panduan_ji = 24
			}
			if(me.user_id != ""){
				me.xuesheng_shuju()
			}else{
				me.panduan = 7
				me.panduan_ji = 24
			}
		},
		onShow() {
			
		}
	}
</script>
<style scoped lang="scss">
	/deep/.van-ellipsis {
		font-size: 30rpx;
	}
	.imp{
		height: 47.112rpx;
		width: 408.37rpx;
		line-height:47.112rpx ;
		text-align: center;
		border-radius: 12.1rpx;
		border: 0.9rpx solid #FF7300;
		font-size: 27.744rpx;
		color: #FFFFFF;
		background: #FF7300;
	}
	.clo{
		color: #C4C4C4;
		border: 0.9rpx solid #C4C4C4;
	}
	.kaike{
		color: #FF7300;
		font-size: 24.744rpx;
		font-weight: bold;
	}
	.ranse{
		color: #FF7300;
	}
	.wu_id{
		height: 126rpx;
	}
	.you_id{
		height: 100rpx;
	}
	.list{
		width: 170rpx;
		height: 47.112rpx;
		background: #FF7300;
		color: #FFFFFF;
		border-radius: 12.1rpx;
		line-height: 47.112rpx;
		text-align: center;
	}
	.znong{
		height: 47.112rpx;
		width: 408.37rpx;
		line-height:47.112rpx ;
		text-align: center;
		border-radius: 12.1rpx;
		font-size: 27.744rpx;
		color: #FFFFFF;
	}
	.list_tan{
		width: 670rpx;
		display: flex;
		justify-content: space-between;
	}
</style>
